#include<stdio.h>
#include<stdlib.h>
#include<at89c51ed2.h>
#include <mcs51reg.h>


void putchar (char c)
{
	while ((SCON & 0x02) == 0);    // wait for TX ready, spin on TI
	SBUF = c;  	// load serial port with transmit value
	TI = 0;  	// clear TI flag
}



void putstr (char *s)  //had return type int in sample file
{
	int i = 0;
	while (*s){			// output characters until NULL found
		putchar(*s++);
		i++;
	}
	putchar('\n');
	}
	
	
char getchar ()__critical
{
	
    while (!RI);             
   	RI = 0;			// clear RI flag
	return SBUF;  	// return character from SBUF
}

void printCustom(char * val){ //basic version of printf,loops putchar till NULL is encountered
	int i=0;
	while(val[i]!='\n'){
		putchar(val[i]);
		i++;
	}
}	
	
void scanF(char* val,int size){  //receives a complete char string from user
		int i=0;
		char * addrSaver;
		char tmp;
		addrSaver=val;
		while ((tmp=getchar())!=13&&i<size)
		{
		
			*addrSaver=tmp;
			addrSaver++;
			i++;
			putchar(tmp);
			
		}
		val[i+1]='\n';
		
		
	}
	

	void clrScr()
	{
		printf_tiny("\033[2J");
	}
	
	void newLine()
		{
			printf_tiny("--------------------------------------------------------------------------------\r\n");
		}
		
	void readCount()
	{
		int Count=0;
			printf("%d:%d",TH0,TL0);
			Count=TH0*255+TL0;
			if(TH0>0&&TL0==0)
			{
			Count++;
			}
		
		
		
		printf("Counter 0:%d\r\n",Count);
	}
	